package main

import (
	"fmt"
	"com.jinxiula/common"
	"io/ioutil"
	"encoding/json"
)

func deal(flag chan<- bool) {
	params:=common.Data()
	params["method"] = "eth_call"
	invokes:=make(map[string]interface{})
	invokes["from"] ="0x70982B82D6EdFDC91B0998c62954e703B7407747"
	invokes["to"] = "0xe37a5a66349c2dd504a83ece918e93283300b635" //合约地址
	//invokes["gas"] = "0x76c0"// 30400
	//invokes["gasPrice"] = "0x9184e72a000" // 10000000000000
	//invokes["value"] = "0x9184e72a" // 2441406250
	invokes["value"] = "0x0"
	invokes["data"] = "0x73d4a13a"
	//invokes["nonce"] = 23
	invokesArray:=make([]interface{},0)
	//顺序不能错
	invokesArray = append(invokesArray,invokes)
	invokesArray = append(invokesArray, "latest")
	params["params"] = invokesArray
	resp:=common.Direct(params)
	defer resp.Body.Close()
	data,_:=ioutil.ReadAll(resp.Body)
	fmt.Println("2)返回的原始数据为:",string(data))
	var result common.Result
	if err:=json.Unmarshal(data,&result);err!=nil{
		flag<-false
		return
	}
	fmt.Println("3)返回的JSON结果：",result)
	flag<-true

}
func main() {
	flag := make(chan bool)
	go deal(flag)
    fmt.Println("返回的调用结果：",<-flag)
}
